package com.mz361.stdapi.controller;

import com.alibaba.fastjson.JSONObject;
import com.mz361.common.utils.ResultVoUtil;
import com.mz361.common.vo.ResultVo;
import com.mz361.component.jwt.annotation.IgnorePermissions;
import com.mz361.modules.system.service.InterpretationVideoService;
import com.mz361.stdapi.domain.*;
import com.mz361.stdapi.service.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;
import redis.clients.jedis.Tuple;

import java.io.IOException;
import java.util.List;
import java.util.Set;


/**
 * @author niceale
 * @ date 2024/04/17
 */
@Api(tags = "满智平台接口")
@RestController
@Slf4j
public class APIController {

    @Autowired
    private STDAPIService stdapiService;
    @Autowired
    private StandardProfileService standardProfileService;
    @Autowired
    private BasicSearchService basicSearchAPIService;
    @Autowired
    private AIRequestService aiRequestService;
    @Autowired
    private StandardDynamicService standardDynamicService;
    @Autowired
    private StandardNoticeService standardNoticeService;
    @Autowired
    private StandardPlanService standardPlanService;
    @Autowired
    private InterpretationVideoService interpretationVideoService;


    @ApiOperation(value = "基础搜索", notes = "基础搜索")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "key", dataType = "String", dataTypeClass = String.class, paramType = "Header", value = "渠道KEY"),
            @ApiImplicitParam(name = "timestamp", dataType = "String", dataTypeClass = String.class, paramType = "Header", value = "时间戳"),
            @ApiImplicitParam(name = "token", dataType = "String", dataTypeClass = String.class, paramType = "Header", value = "token"),
            @ApiImplicitParam(name = "userId", dataType = "String", dataTypeClass = String.class, paramType = "Header", value = "用户ID"),
            @ApiImplicitParam(name = "keyword", dataType = "String", dataTypeClass = String.class, paramType = "query", value = "检索词"),
            @ApiImplicitParam(name = "status", dataType = "String", dataTypeClass = String.class, paramType = "query", value = "有效性状态码"),
            @ApiImplicitParam(name = "standardClass", dataType = "String", dataTypeClass = String.class, paramType = "query", value = "父分类编码"),
            @ApiImplicitParam(name = "classCode", dataType = "String", dataTypeClass = String.class, paramType = "query", value = "所属子分类编码"),
            @ApiImplicitParam(name = "className", dataType = "String", dataTypeClass = String.class, paramType = "query", value = "所属子分类名称"),
            @ApiImplicitParam(name = "havePdf", dataType = "Number", dataTypeClass = Number.class, paramType = "query", value = "是否有电子文本"),
            @ApiImplicitParam(name = "modiDate", dataType = "String", dataTypeClass = String.class, paramType = "query", value = "发布年份"),
            @ApiImplicitParam(name = "draftsMan", dataType = "String", dataTypeClass = String.class, paramType = "query", value = "起草人"),
            @ApiImplicitParam(name = "draftsDept", dataType = "String", dataTypeClass = String.class, paramType = "query", value = "起草单位"),
            @ApiImplicitParam(name = "pageNo", dataType = "Number", dataTypeClass = Number.class, paramType = "query", value = "当前页数，不传默认是1"),
            @ApiImplicitParam(name = "pageSize", dataType = "Number", dataTypeClass = Number.class, paramType = "query", value = "每页条数，不传默认是15")
    })
    @CrossOrigin
    @IgnorePermissions
    @GetMapping("/api/v1/basicSearch")
    public ResultVo basicSearch(@RequestHeader String key, @RequestHeader String timestamp, @RequestHeader String token, @RequestHeader String userId, BasicSearch basicSearch) {
        log.info("basicSearch key = {}, timestamp = {}, token = {}, userId = {}, basicSearch = {}", key, timestamp, token, userId, basicSearch);
        BasicResult basicResult = basicSearchAPIService.basicSearch(userId, basicSearch);
        if (null != basicResult) {
            return ResultVoUtil.success("请求成功", basicResult);
        } else {
            return ResultVoUtil.error("接口错误");
        }
    }

    @ApiOperation(value = "国标免费", notes = "国标免费")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", dataType = "String", dataTypeClass = String.class, paramType = "Header", value = "用户ID"),
            @ApiImplicitParam(name = "keyword", dataType = "String", dataTypeClass = String.class, paramType = "query", value = "检索词"),
            @ApiImplicitParam(name = "status", dataType = "String", dataTypeClass = String.class, paramType = "query", value = "有效性状态码"),
            @ApiImplicitParam(name = "classCode", dataType = "String", dataTypeClass = String.class, paramType = "query", value = "所属子分类编码"),
            @ApiImplicitParam(name = "className", dataType = "String", dataTypeClass = String.class, paramType = "query", value = "所属子分类名称"),
            @ApiImplicitParam(name = "modiDate", dataType = "String", dataTypeClass = String.class, paramType = "query", value = "发布年份"),
            @ApiImplicitParam(name = "draftsMan", dataType = "String", dataTypeClass = String.class, paramType = "query", value = "起草人"),
            @ApiImplicitParam(name = "draftsDept", dataType = "String", dataTypeClass = String.class, paramType = "query", value = "起草单位"),
            @ApiImplicitParam(name = "pageNo", dataType = "Number", dataTypeClass = Number.class, paramType = "query", value = "当前页数，不传默认是1"),
            @ApiImplicitParam(name = "pageSize", dataType = "Number", dataTypeClass = Number.class, paramType = "query", value = "每页条数，不传默认是15")
    })
    @CrossOrigin
    @IgnorePermissions
    @GetMapping("/api/v1/gbFreeSearch")
    public ResultVo gbFreeSearch(@RequestHeader String userId, BasicSearch basicSearch) {
        log.info("gbfreeSearch userId = {}, basicSearch = {}", userId, basicSearch);
        BasicResult basicResult = basicSearchAPIService.gbFreeSearch(userId, basicSearch);
        if (null != basicResult) {
            return ResultVoUtil.success("请求成功", basicResult);
        } else {
            return ResultVoUtil.error("接口错误");
        }
    }

    @ApiOperation(value = "标准解读视频列表", notes = "查询标准解读视频列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "key", dataType = "String", dataTypeClass = String.class, paramType = "Header", value = "渠道KEY", required = true),
            @ApiImplicitParam(name = "timestamp", dataType = "String", dataTypeClass = String.class, paramType = "Header", value = "时间戳", required = true),
            @ApiImplicitParam(name = "token", dataType = "String", dataTypeClass = String.class, paramType = "Header", value = "MD5(KEY+timestamp+密钥)", required = true),
            @ApiImplicitParam(name = "userId", dataType = "String", dataTypeClass = String.class, paramType = "Header", value = "用户ID", required = true),
            @ApiImplicitParam(name = "pageNo", dataType = "Number", dataTypeClass = Number.class, paramType = "query", value = "当前页数，不传默认是0"),
            @ApiImplicitParam(name = "pageSize", dataType = "Number", dataTypeClass = Number.class, paramType = "query", value = "每页条数，不传默认是9")

    })
    @CrossOrigin
    @GetMapping("/api/v1/getVideos")
    @IgnorePermissions
    public ResultVo getVideos(@RequestHeader String userId, Integer pageNo, Integer pageSize) {
        log.info("getVideos userId = {}, pageNo = {}, pageSize = {}", userId, pageNo, pageSize);
        return ResultVoUtil.success("请求成功", interpretationVideoService.getPageList(pageNo, pageSize));
    }

    @ApiOperation(value = "搜索历史", notes = "基于用户的搜索历史")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "key", dataType = "String", dataTypeClass = String.class, paramType = "Header", value = "渠道KEY"),
            @ApiImplicitParam(name = "timestamp", dataType = "String", dataTypeClass = String.class, paramType = "Header", value = "时间戳"),
            @ApiImplicitParam(name = "token", dataType = "String", dataTypeClass = String.class, paramType = "Header", value = "token"),
            @ApiImplicitParam(name = "userId", dataType = "String", dataTypeClass = String.class, paramType = "Header", value = "用户ID")

    })
    @CrossOrigin
    @IgnorePermissions
    @GetMapping("/api/v1/searchHistory")
    public ResultVo<Set<Tuple>> searchHistory(@RequestHeader String key, @RequestHeader String timestamp, @RequestHeader String token, @RequestHeader String userId) {
        log.info("searchHistory key = {}, timestamp = {}, token = {}, userId = {}", key, timestamp, token, userId);
        Set<Tuple> tuples = stdapiService.searchHistory(userId);
        if (null != tuples && !tuples.isEmpty()) {
            return ResultVoUtil.success("请求成功", tuples);
        } else {
            return ResultVoUtil.success("无搜索记录");
        }
    }

    @ApiOperation(value = "清除历史", notes = "清除用户的搜索历史")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "key", dataType = "String", dataTypeClass = String.class, paramType = "Header", value = "渠道KEY"),
            @ApiImplicitParam(name = "timestamp", dataType = "String", dataTypeClass = String.class, paramType = "Header", value = "时间戳"),
            @ApiImplicitParam(name = "token", dataType = "String", dataTypeClass = String.class, paramType = "Header", value = "token"),
            @ApiImplicitParam(name = "userId", dataType = "String", dataTypeClass = String.class, paramType = "Header", value = "用户ID")

    })
    @CrossOrigin
    @IgnorePermissions
    @GetMapping("/api/v1/clearHistory")
    public ResultVo clearHistory(@RequestHeader String key, @RequestHeader String timestamp, @RequestHeader String token, @RequestHeader String userId) {
        log.info("clearHistory key = {}, timestamp = {}, token = {}, userId = {}", key, timestamp, token, userId);
        stdapiService.clearHistory(userId);
        return ResultVoUtil.success("请求成功");

    }

    @ApiOperation(value = "标准概要", notes = "标准概要")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "key", dataType = "String", dataTypeClass = String.class, paramType = "Header", value = "渠道KEY"),
            @ApiImplicitParam(name = "timestamp", dataType = "String", dataTypeClass = String.class, paramType = "Header", value = "时间戳"),
            @ApiImplicitParam(name = "token", dataType = "String", dataTypeClass = String.class, paramType = "Header", value = "token"),
            @ApiImplicitParam(name = "userId", dataType = "String", dataTypeClass = String.class, paramType = "Header", value = "用户ID"),
            @ApiImplicitParam(name = "standardNo", dataType = "String", dataTypeClass = String.class, paramType = "query", value = "标准编号", required = true)

    })
    @CrossOrigin
    @IgnorePermissions
    @GetMapping("/api/v1/standardProfile")
    public ResultVo<StandardData> standardProfile(@RequestHeader String key, @RequestHeader String timestamp, @RequestHeader String token, @RequestHeader String userId, String standardNo) {
        log.info("standardProfile key = {}, timestamp = {}, token = {}, userId = {}, standardNo = {}", key, timestamp, token, userId, standardNo);
        return ResultVoUtil.success("请求成功", standardProfileService.standardProfile(userId, standardNo));
    }

    @ApiOperation(value = "标准文件地址获取", notes = "根据标准号，获取标准文件的地址")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "key", dataType = "String", dataTypeClass = String.class, paramType = "Header", value = "渠道KEY"),
            @ApiImplicitParam(name = "timestamp", dataType = "String", dataTypeClass = String.class, paramType = "Header", value = "时间戳"),
            @ApiImplicitParam(name = "token", dataType = "String", dataTypeClass = String.class, paramType = "Header", value = "token", required = true),
            @ApiImplicitParam(name = "userId", dataType = "String", dataTypeClass = String.class, paramType = "Header", value = "用户ID", required = true),
            @ApiImplicitParam(name = "standardNo", dataType = "String", dataTypeClass = String.class, paramType = "query", value = "标准编号", required = true)

    })
    @CrossOrigin
    @IgnorePermissions
    @GetMapping("/api/v1/fileUrl")
    public ResultVo fileUrl(@RequestHeader String key, @RequestHeader String timestamp, @RequestHeader String token, @RequestHeader String userId, String standardNo) {
        log.info("fileUrl key = {}, timestamp = {}, token = {}, userId = {}, standardNo = {}", key, timestamp, token, userId, standardNo);
        return ResultVoUtil.success("请求成功", stdapiService.fileURL(userId, standardNo));
    }


    @ApiOperation(value = "下载回调", notes = "下载完成后回调接口，用于套餐剩余量变更操作")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "key", dataType = "String", dataTypeClass = String.class, paramType = "Header", value = "渠道KEY"),
            @ApiImplicitParam(name = "timestamp", dataType = "String", dataTypeClass = String.class, paramType = "Header", value = "时间戳"),
            @ApiImplicitParam(name = "token", dataType = "String", dataTypeClass = String.class, paramType = "Header", value = "token", required = true),
            @ApiImplicitParam(name = "userId", dataType = "String", dataTypeClass = String.class, paramType = "Header", value = "用户ID", required = true),
            @ApiImplicitParam(name = "standardNo", dataType = "String", dataTypeClass = String.class, paramType = "query", value = "标准编号", required = true),
            @ApiImplicitParam(name = "title", dataType = "String", dataTypeClass = String.class, paramType = "query", value = "标准名称", required = true)

    })
    @CrossOrigin
    @GetMapping("/api/v1/downLoadNotify")
    public ResultVo downLoadNotify(@RequestHeader String key, @RequestHeader String timestamp, @RequestHeader String token, @RequestHeader String userId, String title, String standardNo) {
        log.info("downLoadNotify key = {}, timestamp = {}, token = {}, userId = {}, title = {}, standardNo = {}", key, timestamp, token, userId, title, standardNo);
        boolean downloadStatus = stdapiService.downLoadNotify(userId, standardNo, title);
        return ResultVoUtil.success("回调通知成功", downloadStatus);
    }


    @ApiOperation(value = "在线阅读回调", notes = "在线阅读回调接口，记录阅读行为")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "key", dataType = "String", dataTypeClass = String.class, paramType = "Header", value = "渠道KEY"),
            @ApiImplicitParam(name = "timestamp", dataType = "String", dataTypeClass = String.class, paramType = "Header", value = "时间戳"),
            @ApiImplicitParam(name = "token", dataType = "String", dataTypeClass = String.class, paramType = "Header", value = "token", required = true),
            @ApiImplicitParam(name = "userId", dataType = "String", dataTypeClass = String.class, paramType = "Header", value = "用户ID", required = true),
            @ApiImplicitParam(name = "standardNo", dataType = "String", dataTypeClass = String.class, paramType = "query", value = "标准编号", required = true),
            @ApiImplicitParam(name = "title", dataType = "String", dataTypeClass = String.class, paramType = "query", value = "标准编号", required = true)

    })
    @CrossOrigin
    @GetMapping("/api/v1/readOnlineNotify")
    public ResultVo readOnlineNotify(@RequestHeader String key, @RequestHeader String timestamp, @RequestHeader String token, @RequestHeader String userId, String title, String standardNo) {
        log.info("readOnlineNotify key = {}, timestamp = {}, token = {}, userId = {}, title = {}, standardNo = {}", key, timestamp, token, userId, title, standardNo);
        boolean readOnlineStatus = stdapiService.readOnLineNotify(userId, standardNo, title);
        return ResultVoUtil.success("回调通知成功", readOnlineStatus);
    }

    @ApiOperation(value = "获取分类信息", notes = "获取分类信息")
    @IgnorePermissions
    @CrossOrigin
    @GetMapping("/api/v1/standardClass")
    public ResultVo standardClass() {

        return ResultVoUtil.success("请求成功", stdapiService.getStandardClass());
    }

    @ApiOperation(value = "获取计划分类信息", notes = "获取计划分类信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "key", dataType = "String", dataTypeClass = String.class, paramType = "Header", value = "渠道KEY"),
            @ApiImplicitParam(name = "timestamp", dataType = "String", dataTypeClass = String.class, paramType = "Header", value = "时间戳"),
            @ApiImplicitParam(name = "token", dataType = "String", dataTypeClass = String.class, paramType = "Header", value = "token"),
            @ApiImplicitParam(name = "userId", dataType = "String", dataTypeClass = String.class, paramType = "Header", value = "用户ID")

    })
    @CrossOrigin
    @IgnorePermissions
    @GetMapping("/api/v1/planClass")
    public ResultVo<List<PlanClass>> planClass(@RequestHeader String key, @RequestHeader String timestamp, @RequestHeader String token, @RequestHeader String userId) {
        log.info("planClass key = {}, timestamp = {}, token = {}, userId = {}", key, timestamp, token, userId);
        return ResultVoUtil.success("请求成功", stdapiService.getPlanClass());
    }


    @ApiOperation(value = "标准计划", notes = "标准计划")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "key", dataType = "String", dataTypeClass = String.class, paramType = "Header", value = "渠道KEY"),
            @ApiImplicitParam(name = "timestamp", dataType = "String", dataTypeClass = String.class, paramType = "Header", value = "时间戳"),
            @ApiImplicitParam(name = "token", dataType = "String", dataTypeClass = String.class, paramType = "Header", value = "token"),
            @ApiImplicitParam(name = "userId", dataType = "String", dataTypeClass = String.class, paramType = "Header", value = "用户ID"),
            @ApiImplicitParam(name = "keyword", dataType = "String", dataTypeClass = String.class, paramType = "query", value = "关键字"),
            @ApiImplicitParam(name = "ccs", dataType = "String", dataTypeClass = String.class, paramType = "query", value = "分类"),
            @ApiImplicitParam(name = "progress", dataType = "String", dataTypeClass = String.class, paramType = "query", value = "项目进度 起草、征求意见、审查、批准、终止"),
            @ApiImplicitParam(name = "durDate", dataType = "String", dataTypeClass = String.class, paramType = "query", value = "时间段 0:近一月,1:近三月,2:近半年,3:近两年,4:近三年"),
            @ApiImplicitParam(name = "pageNo", dataType = "Number", dataTypeClass = Number.class, paramType = "query", value = "当前页数，不传默认是0"),
            @ApiImplicitParam(name = "pageSize", dataType = "Number", dataTypeClass = Number.class, paramType = "query", value = "每页条数，不传默认是8")

    })
    @CrossOrigin
    @IgnorePermissions
    @GetMapping("/api/v1/standardPlans")
    public ResultVo<Page<StandardPlan>> standardPlans(@RequestHeader String key, @RequestHeader String timestamp, @RequestHeader String token, @RequestHeader String userId, PlanSearch planSearch) {
        log.info("standardPlans key = {}, timestamp = {}, token = {}, userId = {}, planSearch = {}", key, timestamp, token, userId, planSearch);
        Page<StandardPlan> plans = standardPlanService.getPageList(planSearch);
        return ResultVoUtil.success("请求成功", plans);
    }

    @ApiOperation(value = "标准计划详情", notes = "标准计划详情")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "key", dataType = "String", dataTypeClass = String.class, paramType = "Header", value = "渠道KEY"),
            @ApiImplicitParam(name = "timestamp", dataType = "String", dataTypeClass = String.class, paramType = "Header", value = "时间戳"),
            @ApiImplicitParam(name = "token", dataType = "String", dataTypeClass = String.class, paramType = "Header", value = "token"),
            @ApiImplicitParam(name = "userId", dataType = "String", dataTypeClass = String.class, paramType = "Header", value = "用户ID"),
            @ApiImplicitParam(name = "standardPlanNo", dataType = "String", dataTypeClass = String.class, paramType = "query", value = "标准编号", required = true)

    })
    @IgnorePermissions
    @CrossOrigin
    @GetMapping("/api/v1/standardPlanInfo")
    public ResultVo<StandardPlan> standardPlanInfo(@RequestHeader String key, @RequestHeader String timestamp, @RequestHeader String token, @RequestHeader String userId, String standardPlanNo) {
        log.info("standardPlanInfo key = {}, timestamp = {}, token = {}, userId = {}, standardPlanNo = {}", key, timestamp, token, userId, standardPlanNo);
        return ResultVoUtil.success("请求成功", standardPlanService.getByStandardPlanNo(standardPlanNo));
    }

    @ApiOperation(value = "标准公告", notes = "标准公告")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "key", dataType = "String", dataTypeClass = String.class, paramType = "Header", value = "渠道KEY"),
            @ApiImplicitParam(name = "timestamp", dataType = "String", dataTypeClass = String.class, paramType = "Header", value = "时间戳"),
            @ApiImplicitParam(name = "token", dataType = "String", dataTypeClass = String.class, paramType = "Header", value = "token"),
            @ApiImplicitParam(name = "userId", dataType = "String", dataTypeClass = String.class, paramType = "Header", value = "用户ID"),
            @ApiImplicitParam(name = "noticeType", defaultValue = "0", dataType = "String", dataTypeClass = Number.class, paramType = "query", value = "公告类型，国家标准公告:0(默认值),行业标准公告:8,地方标准公告:9"),
            @ApiImplicitParam(name = "keyword", dataType = "String", dataTypeClass = String.class, paramType = "query", value = "搜索关键字"),
            @ApiImplicitParam(name = "pageNo", dataType = "Number", dataTypeClass = Number.class, paramType = "query", value = "当前页数，不传默认是0"),
            @ApiImplicitParam(name = "pageSize", dataType = "Number", dataTypeClass = Number.class, paramType = "query", value = "每页条数，不传默认是8")

    })
    @CrossOrigin
    @IgnorePermissions
    @GetMapping("/api/v1/standardNotices")
    public ResultVo<Page<StandardNoticeObj>> standardNotices(@RequestHeader String key, @RequestHeader String timestamp, @RequestHeader String token, @RequestHeader String userId, Integer pageNo, Integer pageSize, String noticeType, String keyword) {
        log.info("standardNotices key = {}, timestamp = {}, token = {}, userId = {}, pageNo = {}, pageSize = {}, noticeType = {}, keyword = {}", key, timestamp, token, userId, pageNo, pageSize, noticeType, keyword);
        return ResultVoUtil.success("请求成功", standardNoticeService.getPageList(noticeType, keyword, pageNo, pageSize));
    }

    @ApiOperation(value = "标准公告详情", notes = "标准公告详情")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "key", dataType = "String", dataTypeClass = String.class, paramType = "Header", value = "渠道KEY"),
            @ApiImplicitParam(name = "timestamp", dataType = "String", dataTypeClass = String.class, paramType = "Header", value = "时间戳"),
            @ApiImplicitParam(name = "token", dataType = "String", dataTypeClass = String.class, paramType = "Header", value = "token"),
            @ApiImplicitParam(name = "userId", dataType = "String", dataTypeClass = String.class, paramType = "Header", value = "用户ID"),
            @ApiImplicitParam(name = "standardNoticeNo", dataType = "String", dataTypeClass = String.class, paramType = "query", value = "计划号", required = true)

    })
    @CrossOrigin
    @IgnorePermissions
    @GetMapping("/api/v1/standardNoticeInfo")
    public ResultVo<StandardNotice> standardNoticeInfo(@RequestHeader String key, @RequestHeader String timestamp, @RequestHeader String token, @RequestHeader String userId, String standardNoticeNo) {
        log.info("standardNoticeInfo key = {}, timestamp = {}, token = {}, userId = {}, standardNoticeNo = {}", key, timestamp, token, userId, standardNoticeNo);
        return ResultVoUtil.success("请求成功", standardNoticeService.getByStandardNoticeNo(standardNoticeNo));
    }

    @ApiOperation(value = "标准动态", notes = "标准动态")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "key", dataType = "String", dataTypeClass = String.class, paramType = "Header", value = "渠道KEY"),
            @ApiImplicitParam(name = "timestamp", dataType = "String", dataTypeClass = String.class, paramType = "Header", value = "时间戳"),
            @ApiImplicitParam(name = "token", dataType = "String", dataTypeClass = String.class, paramType = "Header", value = "token"),
            @ApiImplicitParam(name = "userId", dataType = "String", dataTypeClass = String.class, paramType = "Header", value = "用户ID"),
            @ApiImplicitParam(name = "dynamicStatus", defaultValue = "0", dataType = "String", dataTypeClass = Number.class, paramType = "query", value = "动态类型 0：最新上线（默认），1：即将实施，2：最新被替代，3：最新废止"),
            @ApiImplicitParam(name = "keyword", dataType = "String", dataTypeClass = String.class, paramType = "query", value = "关键字"),
            @ApiImplicitParam(name = "pageNo", dataType = "Number", dataTypeClass = Number.class, paramType = "query", value = "当前页数，不传默认是0"),
            @ApiImplicitParam(name = "pageSize", dataType = "Number", dataTypeClass = Number.class, paramType = "query", value = "每页条数，不传默认是8")

    })
    @CrossOrigin
    @IgnorePermissions
    @GetMapping("/api/v1/standardDynamics")
    public ResultVo<Page<StandardDynamic>> standardDynamics(@RequestHeader String key, @RequestHeader String timestamp, @RequestHeader String token, @RequestHeader String userId, Integer pageNo, Integer pageSize, String dynamicStatus, String keyword) {
        log.info("standardDynamics key = {}, timestamp = {}, token = {}, userId = {}, pageNo = {}, pageSize = {}, dynamicStatus = {}, keyword = {}", key, timestamp, token, userId, pageNo, pageSize, dynamicStatus, keyword);
        return ResultVoUtil.success("请求成功", standardDynamicService.getPageList(dynamicStatus, keyword, pageNo, pageSize));
    }

    @ApiOperation(value = "新建窗口", notes = "根据userID创建会话窗口ID")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "key", dataType = "String", dataTypeClass = String.class, paramType = "Header", value = "渠道KEY"),
            @ApiImplicitParam(name = "timestamp", dataType = "String", dataTypeClass = String.class, paramType = "Header", value = "时间戳"),
            @ApiImplicitParam(name = "token", dataType = "String", dataTypeClass = String.class, paramType = "Header", value = "token"),
            @ApiImplicitParam(name = "userId", dataType = "String", dataTypeClass = String.class, paramType = "Header", value = "用户ID")

    })
    @CrossOrigin
    @IgnorePermissions
    @GetMapping("/api/v1/get_chat_id")
    public ResultVo getChatId(@RequestHeader String userId) {
        return ResultVoUtil.success("请求成功", aiRequestService.getChatId(userId));
    }

    @ApiOperation(value = "保存问答信息", notes = "保存问答信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "key", dataType = "String", dataTypeClass = String.class, paramType = "Header", value = "渠道KEY"),
            @ApiImplicitParam(name = "timestamp", dataType = "String", dataTypeClass = String.class, paramType = "Header", value = "时间戳"),
            @ApiImplicitParam(name = "token", dataType = "String", dataTypeClass = String.class, paramType = "Header", value = "token"),
            @ApiImplicitParam(name = "userId", dataType = "String", dataTypeClass = String.class, paramType = "Header", value = "用户ID"),
            @ApiImplicitParam(name = "chartId", dataType = "String", dataTypeClass = String.class, paramType = "query", value = "会话ID"),
            @ApiImplicitParam(name = "question", dataType = "String", dataTypeClass = String.class, paramType = "query", value = "问题内容"),
            @ApiImplicitParam(name = "answer", dataType = "String", dataTypeClass = String.class, paramType = "query", value = "问题内容")

    })
    @CrossOrigin
    @IgnorePermissions
    @PostMapping("/api/v1/post_answer")
    public ResultVo getAnswer(@RequestHeader String userId, @RequestBody JSONObject postJson) throws IOException {
        String chartId = postJson.getString("chartId");
        String question = postJson.getString("question");
        String answer = postJson.getString("answer");
        aiRequestService.postAnswer(userId, chartId, question, answer);
        return ResultVoUtil.success();
    }

    @ApiOperation(value = "上传会话图片", notes = "上传会话图片")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "key", dataType = "String", dataTypeClass = String.class, paramType = "Header", value = "渠道KEY"),
            @ApiImplicitParam(name = "timestamp", dataType = "String", dataTypeClass = String.class, paramType = "Header", value = "时间戳"),
            @ApiImplicitParam(name = "token", dataType = "String", dataTypeClass = String.class, paramType = "Header", value = "token"),
            @ApiImplicitParam(name = "userId", dataType = "String", dataTypeClass = String.class, paramType = "Header", value = "用户ID"),
            @ApiImplicitParam(name = "imageUrl", dataType = "String", dataTypeClass = String.class, paramType = "query", value = "图片地址")

    })
    @CrossOrigin
    @IgnorePermissions
    @PostMapping("/api/v1/uploadImage")
    public ResultVo uploadImage(@RequestHeader String key, @RequestHeader String timestamp, @RequestHeader String token, @RequestHeader String userId, String imageUrl) throws Exception {
        log.info("key = {}, timestamp = {}, token = {}, userId = {}, imageUrl = {}", key, timestamp, token, userId, imageUrl);
        return ResultVoUtil.success("请求成功", aiRequestService.uploadImage(imageUrl));
    }

    @ApiOperation(value = "获取历史对话", notes = "获取历史对话信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "key", dataType = "String", dataTypeClass = String.class, paramType = "Header", value = "渠道KEY"),
            @ApiImplicitParam(name = "timestamp", dataType = "String", dataTypeClass = String.class, paramType = "Header", value = "时间戳"),
            @ApiImplicitParam(name = "token", dataType = "String", dataTypeClass = String.class, paramType = "Header", value = "token"),
            @ApiImplicitParam(name = "userId", dataType = "String", dataTypeClass = String.class, paramType = "Header", value = "用户ID"),
            @ApiImplicitParam(name = "chartId", dataType = "String", dataTypeClass = String.class, paramType = "query", value = "会话ID")

    })
    @CrossOrigin
    @IgnorePermissions
    @GetMapping("/api/v1/get_history")
    public ResultVo getHistory(@RequestHeader String key, @RequestHeader String timestamp, @RequestHeader String token, @RequestHeader String userId, String chartId) {
        log.info("key = {}, timestamp = {}, token = {}, userId = {}, chartId = {}", key, timestamp, token, userId, chartId);
        return ResultVoUtil.success("请求成功", aiRequestService.getHistory(userId, chartId));
    }


    @ApiOperation(value = "用户套餐信息", notes = "查询用户已购买套餐信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "key", dataType = "String", dataTypeClass = String.class, paramType = "Header", value = "渠道KEY"),
            @ApiImplicitParam(name = "timestamp", dataType = "String", dataTypeClass = String.class, paramType = "Header", value = "时间戳"),
            @ApiImplicitParam(name = "token", dataType = "String", dataTypeClass = String.class, paramType = "Header", value = "token", required = true),
            @ApiImplicitParam(name = "userId", dataType = "String", dataTypeClass = String.class, paramType = "Header", value = "用户ID", required = true)

    })
    @CrossOrigin
    @GetMapping("/api/v1/userPackage")
    public ResultVo<UserPackageResult> userPackage(@RequestHeader String key, @RequestHeader String timestamp, @RequestHeader String token, @RequestHeader String userId) {
        log.info("userPackage key = {}, timestamp = {}, token = {}, userId = {}", key, timestamp, token, userId);
        UserPackageResult userPackageResult = stdapiService.getUserPacakge(userId);
        return ResultVoUtil.success("请求成功", userPackageResult);
    }

    @ApiOperation(value = "套餐信息", notes = "查询套餐列表信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "key", dataType = "String", dataTypeClass = String.class, paramType = "Header", value = "渠道KEY"),
            @ApiImplicitParam(name = "timestamp", dataType = "String", dataTypeClass = String.class, paramType = "Header", value = "时间戳"),
            @ApiImplicitParam(name = "token", dataType = "String", dataTypeClass = String.class, paramType = "Header", value = "token", required = true),
            @ApiImplicitParam(name = "userId", dataType = "String", dataTypeClass = String.class, paramType = "Header", value = "用户ID", required = true)

    })
    @CrossOrigin
    @IgnorePermissions
    @GetMapping("/api/v1/getPackages")
    public ResultVo<PackagesResult> getPackages(@RequestHeader String key, @RequestHeader String timestamp, @RequestHeader String token, @RequestHeader String userId) {
        log.info("getPackages key = {}, timestamp = {}, token = {}, userId = {}", key, timestamp, token, userId);
        return ResultVoUtil.success("请求成功", stdapiService.getPackages(userId));
    }

    @ApiOperation(value = "客户需求", notes = "收集客户需求信息，后续安排专业对接")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "needs", paramType = "query", value = "需求", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "currentStatus", paramType = "query", value = "背景现状", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "conditionsProvided", paramType = "query", value = "可提供条件", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "consultant", paramType = "query", value = "咨询人", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "consultUnit", paramType = "query", value = "咨询单位", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "contact", paramType = "query", value = "联系电话", dataType = "String", dataTypeClass = String.class),

    })
    @CrossOrigin
    @IgnorePermissions
    @PostMapping("/api/v1/custNeeds")
    public ResultVo custNeeds(String needs, String currentStatus, String conditionsProvided, String consultant, String consultUnit, String contact) {
        log.info("custNeeds needs = {}, currentStatus = {}, conditionsProvided = {}, consultant = {}, consultUnit = {}, contact = {}", needs, currentStatus, conditionsProvided, consultant, consultUnit, contact);
        stdapiService.custNeeds(needs, currentStatus, conditionsProvided, consultant, consultUnit, contact);
        return ResultVoUtil.success("保存成功");
    }

}
